package com.example.admin.controller;


import com.example.admin.common.Result;
import com.example.admin.entity.ElderArchive;
import com.example.admin.service.ElderArchiveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.admin.entity.ElderArchive;

import java.util.List;

@RestController
@RequestMapping("/admin")
@CrossOrigin(origins = "http://localhost:8080")
public class ElderArchiveController {

    @Autowired
    private ElderArchiveService elderArchiveService;

    @GetMapping("/selectElderArchivePage")
    public Result<PageInfo> selectElderArchivePage(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {

        PageHelper.startPage(pageNumber,pageSize);
      List<ElderArchive> elderArchivelList= elderArchiveService.selectElderArchivePage();
      return Result.success(new PageInfo(elderArchivelList));

    }

    @DeleteMapping("/deleteElderArchiveById/{id}")
    public Result deleteElderArchiveById(@PathVariable Integer id) {
        Result result=elderArchiveService.deleteElderArchiveById(id);
        return result;
    }


    @PostMapping("/addElderArchive")
    public Result addElderArchive(@RequestBody ElderArchive elderArchive){
    Result result= elderArchiveService.addElderArchive(elderArchive);
    return result;
    }

    @PostMapping("/editeElderArchive")
    public Result editeElderArchive(@RequestBody ElderArchive elderArchive){
       Result result= elderArchiveService.editeElderArchive(elderArchive);
       return result;
    }


    @GetMapping("/selectElderArchiveByName")
    public Result<PageInfo> selectElderArchiveByName(@RequestParam String name) {

        PageHelper.startPage(1,10);
      List<ElderArchive> elderArchiveList=  elderArchiveService.selectElderArchiveByName(name);
      return Result.success(new PageInfo(elderArchiveList));


    }







}
